package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.JobCountData;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    Page<Emp> list(EmpQueryParam empQueryParam);
    //useGeneratedKeys mybatis框架启用生成的主键，数据库的字段必须是主键且自动增长
    //keyProperty 指定主键对应的实体类中的属性名
    //Options作用，把数据库中新增加的主键值赋值给实体类中的id属性
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) values(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    int insert(Emp emp);

    void deleteByIds(@Param("ids") List<Integer> ids);
    @Select("select * from emp where id=#{id}")
    Emp selectById(Integer id);

    Emp getInfoById(Integer id);

    int updateById(Emp emp);
    @Select("""
        select
            case job when 1 then '班主任'
            when 2 then '讲师'
            when 3 then '学工主管'
            when 4 then '教研主管'
            when 5 then '咨询师'
            else '其他'
            end as jobName,
            count(*) as num
        from emp group by job
        order by num;
""")
    List<JobCountData> countEmpJobData();
    @Select( """
    select if(gender=1,'男','女') as name, 
           count(*) as value
    from emp group by gender 
""")
    List<Map<String, Object>> empGenderData();

    @Select("Select  * from emp  where username=#{username} and password=#{password}")
    Emp getInfoByUsernameAndPassword(Emp emp);
}
